var searchMatrix = function (matrix, target) {
    let m = matrix.length, n = matrix[0].length
    let i = 0, j = n - 1

    while (i < m && j >= 0) {
        if (matrix[i][j] === target) {
            return true
        }
        if (matrix[i][j] > target) {
            j--
        } else {
            i++
        }
    }
    return false
};

var searchMatrix = function (matrix, target) {
    // 思路：二维矩阵，从左到右、从上到下升序。从右上角看是一棵二叉搜索树
    let m = matrix.length, n = matrix[0].length;
    let i = 0, j = n - 1;

    while (i < m && j >= 0) {
        if (matrix[i][j] === target) {
            return true;
        }
        if (matrix[i][j] > target) {
            j--;
        } else {
            i++;
        }
    }
    return false;
}